﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace Somnus.IO
{
    public abstract class CopyBeHavior : Behavior
    {
        protected string[] _extension;
        protected string _destDir;
        protected string _srcDir;

        internal override void DoBehavior(params object[] values)
        {
 	        if (values.Length != 1)
                throw new ArgumentException("Invalid parameters,This Method only needs 1 param(s)");
            string srcOrDest = values[0] as string;
            if (srcOrDest == null)
                throw new ArgumentException("Invalid parameters,This Method only needs string type");
            
            SetCurrentRootDir(srcOrDest);

            BeginCopyBehavior();

            Copy();

            EndCopyBehavior();
        }
        protected abstract void SetCurrentRootDir(string srcOrdest);
        protected abstract void Copy();
        protected abstract void BeginCopyBehavior();
        protected abstract void EndCopyBehavior();

        /// <remarks>
        /// If Filter is set to null, Throw exceptions
        /// #2012,12,24###Refactoring#
        /// </remarks>
        public string Filter
        {
            get
            {
                StringBuilder filter = new StringBuilder();
                if (_extension == null)
                {
                    return String.Empty;
                }
                foreach (string ext in _extension)
                {
                    filter.Append(ext + @"|");
                }
                filter.Remove(filter.Length - 1, 1);

                return filter.ToString();
            }
            set
            {
                string updatedFilter = value;
                if (!String.IsNullOrEmpty(updatedFilter))
                {
                    string[] formats = updatedFilter.Split('|');
                    foreach (string format in formats)
                    {
                        if (!format.StartsWith("."))
                        {
                            throw new ArgumentException("Invalid Filter");
                        }
                    }
                    _extension = updatedFilter.Split('|');
                }
                else
                {
                    throw new ArgumentException("Invalid Filter");
                }  
            }
        }


    }
}
